package com.lwlk.util.flow;

import java.util.function.Consumer;
import java.util.function.Function;

public class Chain<T> {

    private T obj;

    private Chain(T obj) { }

    public static <T> Chain<T> of(T obj) {

        return new Chain<>(obj);
    }

    public Chain<T> config(Consumer<T> consumer) {
        consumer.accept(obj); return this;
    }

    public <E> Chain<E> transform(Function<T, E> function) {

        return new Chain<>(function.apply(this.obj));
    }

    public T get() {

        return obj;
    }
}